All Questions
Tagged with variable-substitutionshell-script
90 questions
0votes
0answers
24views
Bash variable losing value [duplicate]
I recently added a variable to a script process that will be used as a replacement value via sed for an output script (not bash). This is one of many variables set within an if statement and (for ...
-1votes
1answer
65views
Output of loop variable shows different value than expected
Imagine I have two folders in my current working directory: back/ and front/. I am trying to enter inside each of them and do some stuff. From the simple script below: for dir in */ ; do echo &...
0votes
2answers
172views
how to replace a string with a variable?
I am trying to write a script containing a loop that enters a series of directories containing the same file, to replace a text string in a file with a variable that matches the directory's name. The ...
5votes
2answers
479views
Issue expanding variable with multiple wildcards in bash shell script with mv / rename
I wrote a bash shell script for Linux to move files in a static folder according to parameters specified in a data file. I've reduced that script to a minimal reproducible example to demonstrate an ...
2votes
3answers
886views
Execute copy commands from file
I have a DE_CopyOldToNew.txt file with a whole bunch of copy commands for copying old file names to new file names. The file contains rows like : cp /migrationfiles/Company\ Name\ GmbH/2014.138_Old\ ...
0votes
4answers
344views
If-else Parameter substitution
I'm running a series of experiments with bash and want to store the log files in a directory whose name is based on the experiment configuration. Some items in the configuration are boolean (true/...
1vote
1answer
45views
Can someone explain this potential variable expansion issue when running smartctl from script vs directly in terminal?
I am trying to write a script that collects some info about disk health as a part of customising ShredOS. I cannot understand what is wrong with the following snippet. #get disk info disk_info=...
-3votes
2answers
1kviews
defining variables inside function
After some reading somewhere on this interwebs, I found that it was best practice to to the following when using the output of a command as a variable: FILE_CORE_NAME="$(/usr/bin/env basename $(/...
0votes
3answers
125views
How to substitute line containing character with text stored in variable with sed?
I have a file entry.txt with a text such as $ cat entry.txt >Main entry This is some text to try how to substitute the first line of the text. I would like to substitute the first line by ...
0votes
2answers
392views
How to grep for the value of a variable inside a shell script?
I have 2 files: a file full of values I want to look for my source text file I wrote a short shell command to loop thru my list of values and grep against my source file. If it doesn't find the ...
0votes
1answer
65views
Shell script: Using variables makes command fails ( substituting values of variables manually ; command works fine )
In a bash script: jenkins_folder=`cut -d "|" -f1 -s input.csv` jenkins_url='https://url.com:8181/jenkins/view/' echo "jenkins_folder : ${jenkins_folder}" for job in ...
0votes
1answer
160views
rtorrent scripting help
rtorrent provides a nice script for moving downloads to a directory based on label or name https://rtorrent-docs.readthedocs.io/en/latest/use-cases.html#versatile-move i'm trying to configure the ...
-3votes
2answers
1kviews
Bash Script - Expand ESCAPED dollar-sign ($) into its Variable
My Problem I have this run.sh script: #!/bin/bash TODAY=$(date) FILE="my_file.txt.\${TODAY}" When I echo FILE I get this: echo ${FILE} Output: `my_file.txt.${TODAY}` But I want this: echo $...
0votes
1answer
2kviews
Prevent splitting command line argument at spaces when running in bash script [duplicate]
I'm trying to run a command in a bash variable, like this: cmd="python -m mymodule 'argument 123 456' argument2=32 argument3=234" $cmd It looks like it is splitting the command line ...
0votes
0answers
136views
How can I use an already defined variable reference in definition of another variable in shell script/ [duplicate]
I am trying to do something like below : export a="ABC" # Works fine export b_"$a"="DEF" # Works fine Now how do I print or echo the new variable "b_$a" ?? I ...